
const regisFunc=(callback) => {
  return function(res){
        var height = res.target;
      var clientHeight = height.clientHeight;
      var scrollTop = height.scrollTop;
      var scrollHeight = height.scrollHeight;
      if (clientHeight + scrollTop + 1 >= scrollHeight) {
        callback&&callback();
      }
  }
}

export var regisScrollEvent = (className, callback) => {
    document
      .getElementsByClassName(className)[0]
      ?.querySelector(".vxe-table--body-wrapper")
      ?.addEventListener(
        "scroll",
        regisFunc(callback) ,
        true
      );
  };

  export var removeScrollEvent = (className) => {
    document
      .getElementsByClassName(className)[0]
      ?.querySelector(".vxe-table--body-wrapper")
      ?.remove("scroll",regisFunc());
  };
  
  export function getQueryString(name) {
      var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
      var r =  decodeURIComponent(window.location.search).substr(1).match(reg);
      if (r != null) {
          return unescape(r[2]);
      }
      return null;
  }


  export function generateRandomString(length) {
    let result = "";
    const characters =
      "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    const charactersLength = characters.length;

    for (let i = 0; i < length; i++) {
      result += characters.charAt(
        Math.floor(Math.random() * charactersLength)
      );
    }

    return result;
  }


  export function prexUrl(){
    return process.env.NODE_ENV === 'dev' ? '' : '/mobile'
  }  